﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Dapper;
using JX.Core;
using JX.Core.Entity;
using JX.Infrastructure.Common;

namespace JX.Dapper
{
	/// <summary>
	/// 数据库表：DownloadErrorLog 的仓储实现类.
	/// </summary>
	public partial class DownloadErrorLogRepositoryDapper : RepositoryDapper<DownloadErrorLogEntity>,IDownloadErrorLogRepositoryDapper
	{	
		/// <summary>
		/// 构造器注入
		/// </summary>
		public DownloadErrorLogRepositoryDapper(DapperDBContext Context, IDapperDBContextFactory dbContextFactory) : base(Context,dbContextFactory)
		{
		}
		
		#region 删除
		/// <summary>
		/// 通过主键删除
		/// </summary>
		/// <returns></returns>
		public virtual bool Delete(int? errorID)
		{
			string strSQL = "delete from DownloadErrorLog where " +
			
			"ErrorID = @ErrorID"; 
			
			var param = new DynamicParameters();
			param.Add("@ErrorID", errorID);
			
			return _Context.Execute(strSQL, param) > 0;
		}
		/// <summary>
		/// 通过主键删除
		/// </summary>
		/// <returns></returns>
		public virtual async Task<bool> DeleteAsync(int? errorID)
		{
			string strSQL = "delete from DownloadErrorLog where " +
			
			"ErrorID = @ErrorID"; 
			
			var param = new DynamicParameters();
			param.Add("@ErrorID", errorID);
			
			return await _Context.ExecuteAsync(strSQL, param) > 0;
		}
		#endregion
		
		#region 得到实体
		/// <summary>
		/// 通过主键返回第一条信息的实体类。
		/// </summary>
		/// <returns></returns>
		public virtual DownloadErrorLogEntity Get(int? errorID)
		{
			string strCondition = string.Empty;
			strCondition += " and ErrorID = @ErrorID";
			
			var param = new DynamicParameters();
			param.Add("@ErrorID", errorID);
			
			return Get(strCondition,param);
		}
		/// <summary>
		/// 通过主键返回第一条信息的实体类。
		/// </summary>
		/// <returns></returns>
		public virtual async Task<DownloadErrorLogEntity> GetAsync(int? errorID)
		{
			string strCondition = string.Empty;
			strCondition += " and ErrorID = @ErrorID";
			
			var param = new DynamicParameters();
			param.Add("@ErrorID", errorID);
			
			return await GetAsync(strCondition,param);
		}
		#endregion
		
		#region 添加
		/// <summary>
		/// 增加一条记录。如果主键没有赋值的话，会生成一个新的主键值。
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public override bool Add(DownloadErrorLogEntity entity)
		{
			if(entity.ErrorID <= 0) entity.ErrorID=GetNewID();
			return base.Add(entity);
		}
		/// <summary>
		/// 增加一条记录。如果主键没有赋值的话，会生成一个新的主键值。
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public override async Task<bool> AddAsync(DownloadErrorLogEntity entity)
		{
			if(entity.ErrorID <= 0) entity.ErrorID=GetNewID();
			return await base.AddAsync(entity);
		}
		/// <summary>
		/// 增加一条记录。如果主键没有赋值的话，会生成一个新的主键值。
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public override int Insert(DownloadErrorLogEntity entity)
		{
			if(entity.ErrorID <= 0) entity.ErrorID=GetNewID();
			return base.Insert(entity);
		}
		/// <summary>
		/// 增加一条记录。如果主键没有赋值的话，会生成一个新的主键值。
		/// </summary>
		/// <param name="entity"></param>
		/// <returns></returns>
		public override async Task<int> InsertAsync(DownloadErrorLogEntity entity)
		{
			if(entity.ErrorID <= 0) entity.ErrorID=GetNewID();
			return await base.InsertAsync(entity);
		}
		#endregion
	}
}